﻿using System;

namespace net.entity.framework.common {
    public static class SqlUtil {
        public static string Literal(object data) {
            var type = data.GetType();

            if (type == typeof (string) || type == typeof (char)) {
                return "'" + data + "'";
            }
            if (type == typeof (int) || type == typeof (double)
                || type == typeof (decimal)) {
                return data.ToString();
            }
            if (type == typeof (DateTime)) {
                var dt = (DateTime) data;
                return dt.ToString("dd MMM yyyy");
            }

            if(type ==typeof(bool)) {
                var isTrue = (bool) data;
                return isTrue ? "1" : "0";
            }
            return data.ToString();
        }
    }
}